<?php
require_once dirname(__FILE__) . '/common/common.inc.php';
require_once dirname(__FILE__) . "/database/$database/database.inc.php";

header('Content-Type: text/plain');

global $myManager;

$orm1 = classToOrm('pz_model');
$orm2 = classToOrm('pz_model_state');
$orm3 = classToOrm('pz_model_transition');

if ($orm1 && $orm2 && $orm3) {
  try {
    $myManager->start_t();
    $models = array();
    $model1 = new stdClass();
    $model1->track_id = MiscUtils::unique();
    $model1->name = 'Personal';
    array_push($models, $model1);
    
    $states = array();
    $state6 = new stdClass();
    $state6->track_id = MiscUtils::unique();
    $state6->model_id = 3;
    $state6->name = 'New Task';
    
    $state7 = new stdClass();
    $state7->track_id = MiscUtils::unique();
    $state7->model_id = 3;
    $state7->name = 'Questioned';
    
    $state8 = new stdClass();
    $state8->track_id = MiscUtils::unique();
    $state8->model_id = 3;
    $state8->name = 'Reopened';
    
    $state9 = new stdClass();
    $state9->track_id = MiscUtils::unique();
    $state9->model_id = 3;
    $state9->name = 'Task is completed';
    
    $state10 = new stdClass();
    $state10->track_id = MiscUtils::unique();
    $state10->model_id = 3;
    $state10->name = 'Task is comfirmed';
    
    array_push($states, $state6, $state7, $state8, $state9, $state10);
    
    $transitions = array();
    $transition12 = new stdClass();
    $transition12->track_id = MiscUtils::unique();
    $transition12->model_id = 3;
    $transition12->source_id = 17;
    $transition12->target_id = 20;
    $transition12->name = 'Done';
    $transition12->user_type = '';
    $transition12->day = 3;
    
    $transition13 = new stdClass();
    $transition13->track_id = MiscUtils::unique();
    $transition13->model_id = 3;
    $transition13->source_id = 17;
    $transition13->target_id = 18;
    $transition13->name = 'Ask';
    $transition13->user_type = '';
    $transition13->day = 3;
    
    $transition14 = new stdClass();
    $transition14->track_id = MiscUtils::unique();
    $transition14->model_id = 3;
    $transition14->source_id = 18;
    $transition14->target_id = 19;
    $transition14->name = 'Answer';
    $transition14->user_type = '';
    $transition14->day = 3;
    
    $transition15 = new stdClass();
    $transition15->track_id = MiscUtils::unique();
    $transition15->model_id = 3;
    $transition15->source_id = 19;
    $transition15->target_id = 20;
    $transition15->name = 'Done';
    $transition15->user_type = '';
    $transition15->day = 3;
    
    $transition16 = new stdClass();
    $transition16->track_id = MiscUtils::unique();
    $transition16->model_id = 3;
    $transition16->source_id = 19;
    $transition16->target_id = 18;
    $transition16->name = 'Ask';
    $transition16->user_type = '';
    $transition16->day = 3;
    
    $transition17 = new stdClass();
    $transition17->track_id = MiscUtils::unique();
    $transition17->model_id = 3;
    $transition17->source_id = 20;
    $transition17->target_id = 21;
    $transition17->name = 'Confirm';
    $transition17->user_type = '';
    $transition17->day = 999;

    array_push($transitions, $transition12, $transition13, $transition14, $transition15, $transition16, $transition17);
    
    foreach($models as &$model) {
      $orm1->add($myManager, $model);
    }
    
    foreach($states as &$state) {
      $orm2->add($myManager, $state);
    }
    foreach($transitions as &$transition) {
      $orm3->add($myManager, $transition);
    }
    
    $myManager->commit_t();

    echo json_encode(array());
  } catch (PDOException $e) {
    echo $e->getMessage();
  }
}
?>